package com.se.aiClient;

import com.se.common.UserInformation;
import com.se.db.DbUserInformation;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.SQLException;

public class AIClientUtils {
    private static final Logger logger = LoggerFactory.getLogger(AIClientUtils.class);

    public static String promptCreator(String id, String message, String key, String url,
                                       String model, double temperature, String primaryPrompt) {
        JSONObject json = new JSONObject();
        json.put("apiId", id);
        json.put("message", message);
        json.put("apiKey", key);
        json.put("baseUrl", url);
        json.put("model", model);
        json.put("temperature", temperature);
        json.put("primary_prompt", primaryPrompt);

        String prompt = json.toString();
        logger.info("创建了新的提示词: {}", prompt);
        return prompt;
    }

    public static String createNewAI(String username) throws SQLException {
        UserInformation information = DbUserInformation.getInstance().get(username);
        return username + "-" + information.getAIList().size();
    }

    public static String getCleanedString(String str) {

        String regex = "[^\\p{Script=Han}a-zA-Z0-9，。！？：、；《》（）~()\\s]";

        String cleaned = str.replaceAll(regex, "");
        cleaned = cleaned.replaceAll("\\s+", " ");

        return cleaned.trim();
    }

    private AIClientUtils(){
    }
}
